package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.wx_user.WXSetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "套餐浏览接口接口")
public class SetmealController {
    @Autowired
    private WXSetmealService wxSetmealService;
    /**
     * 条件查询
     *
     * @param categoryId
     * @return
     */
    // SpringCache使用，@Cacheable先查缓存，命中直接返回，否则调用方法，并将返回值存入缓存
    @Cacheable(cacheNames = "setmeal", key="#categoryId")
    @ApiOperation("根据分类id查询套餐")
    @GetMapping("/list")
    public Result<List<Setmeal>> list(Long categoryId) {
        log.info("根据分类id查询套餐：{}", categoryId);
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(categoryId);
        setmeal.setStatus(StatusConstant.ENABLE);
        List<Setmeal> list = wxSetmealService.list(setmeal);
        return Result.success(list);
    }
    //根据套餐id查询包含的菜品
    @Cacheable(cacheNames = "setmeal", key="#id")
    @ApiOperation("根据套餐id查询包含的菜品")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> dishList(@PathVariable("id")  Long id) {
        log.info("根据套餐id查询包含的菜品：{}", id);
        List<DishItemVO> list = wxSetmealService.dishList(id);
        return Result.success(list);
    }
}
